package com.qf.day12.homework2;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class TextEditorImpl implements TextEditorService{
    private LinkedList<String>linkedList=new LinkedList<>();
    @Override
    public boolean addLine(String line) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入想插入的数据");
        String s=scanner.nextLine();
        linkedList.add(s);
        return false;
    }

    @Override
    public List<String> getALl() {
        return linkedList;
    }

    @Override
    public boolean updateLine(int lineNum, String line) {
        if(lineNum>linkedList.size()||lineNum<1){
            System.out.println("没有这行");
            return false;
        }
        linkedList.remove(lineNum-1);
        linkedList.add(lineNum-1,line);
        return true;
    }

    @Override
    public boolean deleteLine(int lineNum) {
        if(lineNum>linkedList.size()||lineNum<1){
            System.out.println("没有这行");
            return false;
        }
        linkedList.remove(lineNum-1);
        return true;
    }

    @Override
    public boolean insertLine(int lineNum, String line) {
        if(lineNum>linkedList.size()||lineNum<1){
            System.out.println("没有这行");
            return false;
        }
        linkedList.add(lineNum-1,line);
        return true;
    }

}
